/**
 * Copyright (C) 2010 David Simonek <dafesimonek@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dafe.partyband.db.model;

import com.db4o.types.Blob;
import java.io.File;
import org.dafe.partyband.db.api.ISong;
import org.dafe.partyband.db.api.ISongResource;

/**
 *
 * @author dafe
 */
public class SongResource implements ISongResource {

    private String mimeType;
    private String filePath;
    private String description;
    private Blob blob;
    private long length;
    private long lastModified;
    private String pathSep;
    private boolean preferred;
    private ISong parent;
    
    private static final String WIN_PATH_SEP = "\\";
    private static final String UNIX_PATH_SEP = "/";

    public SongResource(String mimeType, String filePath, String description) {
        this(mimeType, filePath, description, 0, 0);
    }

    public SongResource(String mimeType, String filePath, String description, long length, long lastModified) {
        this.mimeType = mimeType;
        this.filePath = filePath;
        this.description = description;
        this.length = length;
        this.lastModified = lastModified;
        this.pathSep = File.separator;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public Blob getBlob() {
        return blob;
    }

    public long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public long getLastModified() {
        return lastModified;
    }

    public void setLastModified(long lastModified) {
        this.lastModified = lastModified;
    }

    public String getPathSeparator() {
        return pathSep;
    }

    public void setPathSeparator(String pathSep) {
        this.pathSep = pathSep;
    }

    public String getFileName() {
        int pathSepIndex = filePath.lastIndexOf(pathSep);
        if (pathSepIndex < 0) {
            pathSepIndex = filePath.lastIndexOf(WIN_PATH_SEP);
            if (pathSepIndex < 0) {
                pathSepIndex = filePath.lastIndexOf(UNIX_PATH_SEP);
            }
        }
        return filePath.substring(pathSepIndex + pathSep.length(),
                                    filePath.length());
    }

    public boolean isPreferred() {
        return preferred;
    }

    public void setPreferred(boolean preferred) {
        this.preferred = preferred;
    }

    public ISong getParent() {
        return parent;
    }

    public void setParent(ISong song) {
        this.parent = song;
    }

}
